#pragma once

#ifndef DLL_BBOUT_H
#define DLL_BBOUT_H
#endif

using namespace std;

// DeclsDll .lib "bbAddon.dll"
/*======================================================================*/
/*                             Peek Memory                              */
/*======================================================================*/

// DeclsInfo : Peek Memory

BBAEXPfloat PeekMF( int addr );
BBAEXPint PeekMB( int addr );
BBAEXPint PeekMS( int addr );
BBAEXPint PeekMI( int addr );
BBAEXPvoid PokeMB( unsigned char *addr , int b);
BBAEXPvoid PokeMS( unsigned char *addr , int s);
BBAEXPvoid PokeMI( unsigned char *addr , int i);
BBAEXPvoid PokeMF( unsigned char *addr , float f);
BBAEXPstring GetString( const char*addr );
BBAEXPstring GetTypeString( int addr ,int FieldId);
BBAEXPint GetTypeInt( int addr ,int FieldId);
BBAEXPfloat GetTypeFloat( int addr ,int FieldId);
	

/*======================================================================*/
/*                             Array SDK                                */
/*======================================================================*/

/* DeclsInfo : Array SDK
*---------------------------*
|Fast Bank/Array for Blitz3D|
*---------------------------*
-> Create an array of the specified size
		Local Array		=	NewArray		( Size Of Array In Byte )
	-> resize the specified array
							ArrayResize		( Array, NewSize )
	-> return the Size of the specified Array
		Local Size%		=	ArraySize		( Array )
	-> Release the specified Array
							FreeArray		( Array )
	-> Set/Get datas from array at specified offset
							PokeArray		( Array, Offset, Byte )
							PokeArrayI		( Array, Offset, Byte )
							PokeArrayF		( Array, Offset, Byte )
		Local MyByte	=	PeekArray		( Array, Offset )
		Local MyInt%	=	PeekArrayI		( Array, Offset )
		Local MyFloat#	=	PeekArrayF		( Array, Offset )
*---------------------------*
*/

BBAEXPint NewArray( int size );
BBAEXPvoid ArrayResize( achar Arr, int size );
BBAEXPint ArraySize( achar Arr );
BBAEXPvoid FreeArray( achar Arr);
BBAEXPvoid PokeArray( achar Arr, int o, uchar c );
BBAEXPvoid PokeArrayI( achar Arr, int o, int v );
BBAEXPvoid PokeArrayF( achar Arr, int o, float f );
BBAEXPint PeekArray( achar Arr, int o );
BBAEXPint PeekArrayI( achar Arr, int o );
BBAEXPfloat PeekArrayF( achar Arr, int o );
BBAEXPvoid PokeArraySafe( achar Arr, int o, uchar c );
BBAEXPvoid PokeArraySafeI( achar Arr, int o, int v );
BBAEXPvoid PokeArraySafeF( achar Arr, int o, float f );
BBAEXPint PeekArraySafe( achar Arr, int o );
BBAEXPint PeekArraySafeI( achar Arr, int o );
BBAEXPfloat PeekArraySafeF( achar Arr, int o );


/*======================================================================*/
/*						 Basic Maths */
/*======================================================================*/

// DeclsInfo : Basic Maths

BBAEXPcfloat Clamp(float v, float min,float max);
BBAEXPcfloat RadToDeg(const float a);
BBAEXPcfloat DegToRad(const float a);
BBAEXPcfloat Min( const float a, const float b );
BBAEXPcfloat Max( const float a, const float b );
BBAEXPcfloat LinearInterp ( const float a, const float b, const float rate );
BBAEXPcfloat CosInterp ( const float a, const float b, const float rate );
BBAEXPcfloat CubicInterp(const float a,const float b,const float c,const float d,const float rate);


/*======================================================================*/
/*						 HD Timer */
/*======================================================================*/

// DeclsInfo : HD Timer

BBAEXPint HDTSupport ();
BBAEXPint CreateCounter (void);
BBAEXPvoid ResetCounter ( TCounter* counter );
BBAEXPint CounterTime ( TCounter* counter );
BBAEXPint CounterElasped ( TCounter* counter );
BBAEXPvoid CounterFree ( TCounter* counter );
BBAEXPfloat PITClock();
BBAEXPint Millisecondes();
BBAEXPint SystemCounter();
BBAEXPvoid ResetClock ();
BBAEXPint MicroSecs ();
BBAEXPint ComputerTime ();
BBAEXPint CounterStartedAt ( TCounter* counter );
BBAEXPint ElapsedTime ();
BBAEXPfloat AppMicroCoef ();


/*======================================================================*/
/*						 Events */
/*======================================================================*/

// DeclsInfo : Events

BBAEXPvoid EmitEvent(int Event_Id,int Event_X,int Event_Y,char* Event_Data,int Event_Source);
BBAEXPint PollEvent();
BBAEXPint EventID();
BBAEXPint EventX();
BBAEXPint EventY();
BBAEXPint EventSource();
BBAEXPstr EventData();
BBAEXPvoid EventEnableStack(int enable);
BBAEXPint EventStackEnabled();
BBAEXPvoid SetEventStackSize(int Size);
BBAEXPint EventStackSize();
BBAEXPint CountEvents();


/*======================================================================*/
/*						 Linked List */
/*======================================================================*/

// DeclsInfo : Linked List

BBAEXPvoid DeleteList (TList * list);
BBAEXPvoid DeleteLink (TLink * lnk);
BBAEXPvoid SetLinkValue (TLink* lnk, const char* datas);
BBAEXPint NewList();
BBAEXPint CopyList(TList*List);
BBAEXPint InsertAfter(TLink* lnk, TLink* after);
BBAEXPint InsertBefore(TLink* lnk, TLink* before);
BBAEXPint AddLast(TList* list, const char* pValue);
BBAEXPint AddFirst(TList* list, const char* pValue);
BBAEXPint ListCount(TList* list);
BBAEXPint ListFind(TList* list, const char* value);
BBAEXPcint ListIsEmpty(const TList* list);
BBAEXPcint ListFirst(const TList* list);
BBAEXPcint ListLast(const TList* list);
BBAEXPcint AfterLink(TLink* link);
BBAEXPcint BeforeLink(TLink* link);
//BBAEXPint len(const char* a);
BBAEXPint LinkCompare(TLink* l1, TLink* l2);
BBAEXPint StrCompare(const char* a, const char* b);
BBAEXPstr LinkValue(TLink* link);
BBAEXPstr LinkKey(TLink* link);
BBAEXPint SwapLinks(TLink* l1, TLink* l2);
BBAEXPint SortList(TList* list, int sens);
BBAEXPint LinkList(TLink* link);


/*======================================================================*/
/*						 STD::map */
/*======================================================================*/

// DeclsInfo : std::map

BBAEXPint NewMap();
BBAEXPint CopyMap(tmap*map);
BBAEXPvoid MapClear(tmap&map);
BBAEXPvoid DeleteMap(tmap*map);
BBAEXPvoid MapInsert(tmap&map, const char*k, const char*v);
BBAEXPvoid MapModify(tmap&map, const char*k, const char*v);
BBAEXPcint MapCount(tmap&map);
BBAEXPcint MapContains(tmap&map,const char* key);
BBAEXPcint MapIsEmpty(tmap&map);
BBAEXPstring MapFind(tmap&map, const char*k);
BBAEXPvoid MapRemove(tmap&map, const char*k);
BBAEXPcint MapList(tmap &map);
BBAEXPcint ListMap(TList &list);


/*======================================================================*/
/*						 Tree Nodes */
/*======================================================================*/

// DeclsInfo : Tree Nodes = base-class for Hierarchy

BBAEXPcint NewNode(const char* obj, TNode* parent);
BBAEXPcint CopyNode(TNode*Source, TNode*Parent);
BBAEXPvoid DeleteNode(TNode*node);

BBAEXPcint CountNodes(TNode*node);
BBAEXPstr NodeObject(TNode*node);
BBAEXPvoid SetNode(TNode*node, const char* pObject);
BBAEXPcint AfterNode(TNode*node);
BBAEXPcint BeforeNode(TNode*node);
BBAEXPcint NodeFirst(TNode*node);
BBAEXPcint NodeLast(TNode*node);
BBAEXPcint GetNode(TNode*node, int id);
BBAEXPcint NodeFind(TNode*node, const char* obj);
BBAEXPcint NodeParent(TNode* node);
BBAEXPcint ParentNode(TNode* node, TNode* parent);



/*======================================================================*/
/*         Tokenize a string and return a Linked-List object */
/*======================================================================*/

// DeclsInfo : Tokenizer

BBAEXPint Tokenize(const char* mystring, const char* delimiters, const char* Symbols);


/*======================================================================*/
/*                   "Fake"-Class for scripting */
/*======================================================================*/

// DeclsInfo : Script SDK

BBAEXPcint cDebugCountcscriptObjs ();
BBAEXPcint cClass(const char* Name);
BBAEXPcint cNew(cscriptClass*Class);
BBAEXPcint cClose();
BBAEXPcint cField(const char* signature);
BBAEXPstr cClassName(cscriptClass*Class);
BBAEXPvoid cClassDel (const cscriptClass * Class);
BBAEXPvoid cObjDel (const cscriptObj * obj);
BBAEXPvoid cSet (cscriptObj* obj, const char* datas, int fieldId);
BBAEXPstr cGet (cscriptObj* obj, int fieldId);
BBAEXPvoid cInsert(cscriptObj* obj, cscriptObj* after);
BBAEXPcint cFirst(cscriptClass* Class);
BBAEXPcint cLast(cscriptClass* Class);
BBAEXPcint cBefore(cscriptObj* obj);
BBAEXPcint cAfter(cscriptObj* obj);
BBAEXPcint cFind(const char* Name);

BBAEXPcint cFirstClass();
BBAEXPcint cLastClass();

/*======================================================================*/
/*                   Vector2 */
/*======================================================================*/

// DeclsInfo : Vector2

BBAEXPcint NewV2(const float x, const float y);
BBAEXPcint V2Equal(vector2* v1, vector2* v2);
BBAEXPcint V2Add(vector2& v1,vector2* v2);
BBAEXPcint V2Sub(vector2& v1,vector2* v2);
BBAEXPvoid ScaleV2(vector2* v,float f);
BBAEXPstring V2ToString(vector2* v);
BBAEXPvoid SetV2(vector2* v, const float x, const float y);
BBAEXPvoid SetV2X(vector2* v, const float x);
BBAEXPvoid SetV2Y(vector2* v, const float y);
BBAEXPcint DeleteV2(vector2* v);
BBAEXPcfloat V2X(vector2* v);
BBAEXPcfloat V2Y(vector2* v);
BBAEXPcfloat V2Mag(vector2* v);
BBAEXPcfloat V2SquareMag(vector2* v);
BBAEXPcfloat V2Dot(vector2* v1, vector2* v2);
BBAEXPcfloat V2Cross(vector2* v1, vector2* v2);
BBAEXPvoid MagV2(vector2* v);
BBAEXPcint NormalizedV2(vector2* v);
BBAEXPcfloat V2Angle(vector2* v1,vector2* v2);
BBAEXPcfloat V2Yaw(vector2* v);
BBAEXPvoid V2Clear(vector2* v);


/*======================================================================*/
/*                   Vector2 List */
/*======================================================================*/

// DeclsInfo : Vector2 List

BBAEXPvoid DeleteV2List (vector2list * list);
BBAEXPvoid DeleteV2Link (vector2link * lnk);
BBAEXPvoid SetV2Vector (vector2link* lnk, vector2* vector);
BBAEXPint NewV2List();
BBAEXPint CopyV2List(vector2list*List);
BBAEXPint V2InsertAfter(vector2link* lnk, vector2link* after);
BBAEXPint V2InsertBefore(vector2link* lnk, vector2link* before);
BBAEXPint V2AddLast(vector2list* list, vector2* vector);
BBAEXPint V2AddFirst(vector2list* list, vector2* vector);
BBAEXPint V2ListCount(vector2list* list);
BBAEXPint V2Contains(vector2list* list, vector2* vector);
BBAEXPcint V2ListIsEmpty(const vector2list* list);
BBAEXPcint V2FirstLink(const vector2list* list);
BBAEXPcint V2LastLink(const vector2list* list);
BBAEXPcint V2AfterLink(const vector2link* link);
BBAEXPcint V2BeforeLink(const vector2link* link);
BBAEXPcint V2vector(const vector2link* link);


/*======================================================================*/
/*                   Vector3 */
/*======================================================================*/

// DeclsInfo : Vector3

BBAEXPcint NewVector3(const float x, const float y, const float z);
BBAEXPcint Vector3Equal(vector3* v1, vector3* v2);
BBAEXPvoid SetVector3(vector3* v, const float x, const float y, const float z);
BBAEXPstring vector3ToString(vector3* v);
BBAEXPvoid SetVector3X(vector3* v, const float x);
BBAEXPvoid SetVector3Y(vector3* v, const float y);
BBAEXPvoid SetVector3Z(vector3* v, const float z);
BBAEXPcint DeleteVector3(vector3* v);
BBAEXPcfloat Vector3X(vector3* v);
BBAEXPcfloat Vector3Y(vector3* v);
BBAEXPcfloat Vector3Z(vector3* v);
BBAEXPcfloat Vector3Mag(vector3* v);
BBAEXPcfloat Vector3SquareMag(vector3* v);
BBAEXPcfloat Vector3Dot(vector3* v1, vector3* v2);
BBAEXPcint Vector3Cross(vector3* v1, vector3* v2);
BBAEXPvoid MagVector3(vector3* v);
BBAEXPcint NormalizedVector3(vector3* v);
BBAEXPcfloat Vector3Angle(vector3* v1,vector3* v2);
BBAEXPcfloat Vector3Yaw(vector3* v);
BBAEXPcfloat Vector3Pitch(vector3* v);
BBAEXPvoid Vector3Clear(vector3* v);


/*======================================================================*/
/*                   Vector3 List */
/*======================================================================*/

// DeclsInfo : Vector3 List

BBAEXPvoid DeleteVector3List (vector3list * list);
BBAEXPvoid DeleteVector3Link (vector3link * lnk);
BBAEXPvoid SetVector3Vector (vector3link* lnk, vector3* vector);
BBAEXPint NewVector3List();
BBAEXPint CopyVector3List(vector3list*List);
BBAEXPint Vector3InsertAfter(vector3link* lnk, vector3link* after);
BBAEXPint Vector3InsertBefore(vector3link* lnk, vector3link* before);
BBAEXPint Vector3AddLast(vector3list* list, vector3* vector);
BBAEXPint Vector3AddFirst(vector3list* list, vector3* vector);
BBAEXPint Vector3ListCount(vector3list* list);
BBAEXPint Vector3Contains(vector3list* list, vector3* vector);
BBAEXPcint Vector3ListIsEmpty(const vector3list* list);
BBAEXPcint Vector3FirstLink(const vector3list* list);
BBAEXPcint Vector3LastLink(const vector3list* list);
BBAEXPcint Vector3AfterLink(const vector3link* link);
BBAEXPcint Vector3BeforeLink(const vector3link* link);
BBAEXPcint Vector3vector(const vector3link* link);


/* DeclsInfo :
*==============*
*____Bullet____*
*==============*
*/

//#include "btBulletCollisionCommon.h"
//#include "btBulletDynamicsCommon.h"

/*======================================================================*/
/*                          btVector3 */
/*======================================================================*/

// DeclsInfo : btVector3

BBAEXPvoid DeleteV3(btVector3* v);
BBAEXPcint NewV3(float x,float y,float z);
BBAEXPcint V3add(btVector3& v1, btVector3& v2);
BBAEXPcint V3sub(btVector3& v1, btVector3& v2);
BBAEXPcfloat V3x(btVector3* v);
BBAEXPcfloat V3y(btVector3* v);
BBAEXPcfloat V3z(btVector3* v);
BBAEXPcfloat V3w(btVector3* v);
BBAEXPvoid V3set(btVector3* v, float x, float y, float z);
BBAEXPvoid V3setX(btVector3* v, float x);
BBAEXPvoid V3setY(btVector3* v, float y);
BBAEXPvoid V3setZ(btVector3* v, float z);
BBAEXPvoid V3setW(btVector3* v, float w);
BBAEXPvoid V3setMax(btVector3* v1, btVector3& v2);
BBAEXPvoid V3setMin(btVector3* v1, btVector3& v2);
BBAEXPvoid V3getSkewSymmetricMatrix(btVector3* v, btVector3* v0,btVector3* v1,btVector3* v2);
BBAEXPvoid V3setZero(btVector3* v);
BBAEXPcint V3isZero(btVector3* v);
BBAEXPcint V3fuzzyZero(btVector3* v);
BBAEXPcint V3equal(const btVector3& v, const btVector3& v2);
BBAEXPcint V3notEqual(const btVector3& v, const btVector3& v2);
BBAEXPcint V3mulScalar(btVector3&v, float f);
BBAEXPcint V3divScalar(btVector3&v, float f);
BBAEXPcfloat V3dot(btVector3*v, btVector3& v2);
BBAEXPcfloat V3length2(btVector3*v);
BBAEXPcfloat V3length(btVector3*v);
BBAEXPcfloat V3distance2(btVector3*v, btVector3& v2);
BBAEXPcfloat V3distance(btVector3*v, btVector3& v2);
BBAEXPcint V3safeNormalize(btVector3*v);
BBAEXPcint V3normalize(btVector3*v);
BBAEXPcint V3normalized(btVector3*v);
BBAEXPcint V3rotate(btVector3*v,btVector3& wAxis,float angle);
BBAEXPcfloat V3angle(btVector3*v, btVector3& v2);
BBAEXPcint V3absolute(btVector3*v);
BBAEXPcint V3cross(btVector3*v, btVector3& v2);
BBAEXPcfloat V3triple(btVector3*v, btVector3& v1, btVector3& v2);
BBAEXPcint V3minAxis(btVector3*v);
BBAEXPcint V3maxAxis(btVector3*v);
BBAEXPcint V3furthestAxis(btVector3*v);
BBAEXPcint V3closestAxis(btVector3*v);
BBAEXPvoid V3setInterpolate3(btVector3*v, btVector3& v0, btVector3& v1, float rt);
BBAEXPvoid V3lerp(btVector3*v, btVector3& v2, float t);

BBAEXPcfloat V3yaw(btVector3*v);
BBAEXPcfloat V3pitch(btVector3*v);

BBAEXPstring V3ToString(btVector3& v);

/*======================================================================*/
/*                   btVector3 List */
/*======================================================================*/

// DeclsInfo : btVector3 List

BBAEXPvoid DeleteV3List (btV3List * list);
BBAEXPvoid DeleteV3Link (btV3Link * lnk);
BBAEXPvoid SetV3Vector (btV3Link* lnk, btVector3* vector);
BBAEXPvoid SetV3Link (btV3Link* lnk, const float x, const float y, const float z);
BBAEXPfloat V3LinkX (btV3Link* lnk);
BBAEXPfloat V3LinkY (btV3Link* lnk);
BBAEXPfloat V3LinkZ (btV3Link* lnk);
BBAEXPint NewV3List();
BBAEXPint CopyV3List(btV3List*List);
BBAEXPint V3InsertAfter(btV3Link* lnk, btV3Link* after);
BBAEXPint V3InsertBefore(btV3Link* lnk, btV3Link* before);
BBAEXPint V3AddLast(btV3List* list, btVector3* vector);
BBAEXPint V3AddFirst(btV3List* list, btVector3* vector);
BBAEXPint V3ListCount(btV3List* list);
BBAEXPint V3Contains(btV3List* list, btVector3* vector);
BBAEXPcint V3ListIsEmpty(btV3List* list);
BBAEXPcint V3First(btV3List* list);
BBAEXPcint V3Last(btV3List* list);
BBAEXPcint V3After(btV3Link* link);
BBAEXPcint V3Before(btV3Link* link);
BBAEXPcint V3Get(btV3Link* link);








/*======================================================================*/
/*                             BULLET */
/*======================================================================*/

/* DeclsInfo : BULLET
* Contains structur for vector3 matrix9 and dynamic collisions
*/

//#include "btBulletCollisionCommon.h"
//#include "btBulletDynamicsCommon.h"
//#include "BulletCollision/CollisionShapes/btBox2dShape.h"
//#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
//#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
//#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btMatrix3x3.h"
#include "LinearMath/btMinMax.h"

/*======================================================================*/
/*                          btBox2DShape */
/*======================================================================*/

//BBAEXPcint ShapeHalfExtents(btBox2dShape & shape, int WithMargin);

/*======================================================================*/
/*                          btMatrix3x3 */
/*======================================================================*/

// DeclsInfo : btMatrix3x3
BBAEXPfloat Convm9tobbVec (int i, int j);

BBAEXPcint NewM9();
BBAEXPcint NewM9FromQuat(btQuaternion& q);
BBAEXPcint CreateM9(
					float xx,float xy,float xz,
					float yx,float yy,float yz,
					float zx,float zy,float zz
				   );
BBAEXPcint CopyM9(btMatrix3x3& m);
BBAEXPcint M9add(btMatrix3x3& m,btMatrix3x3& m2);
BBAEXPcint M9sub(btMatrix3x3& m,btMatrix3x3& m2);
BBAEXPcint M9mul (btMatrix3x3& m, btMatrix3x3& m2);
BBAEXPfloat M9get(btMatrix3x3& m, int i, int j);
BBAEXPcint M9getColumn(btMatrix3x3& m, int i);
BBAEXPcint M9getRow(btMatrix3x3& m, int i);
BBAEXPcint M9setValue (btMatrix3x3& m, 
						 float xx, float xy, float xz,
						 float yx, float yy, float yz,
						 float zx, float zy, float zz);
BBAEXPcint M9setRotation (btMatrix3x3& m, btQuaternion &q);
BBAEXPcint M9setEulerYPR (btMatrix3x3& m, float yaw, float pitch, float roll);
BBAEXPcint M9setEulerZYX (btMatrix3x3& m, float eulerX, float eulerY, float eulerZ);
BBAEXPcint M9setIdentity (btMatrix3x3& m);
BBAEXPcint M9getQuat (btMatrix3x3& m, btQuaternion&q);
BBAEXPcint M9getEulerYPR (btMatrix3x3& m, btVector3& Result);
BBAEXPcint M9getEulerZYX (btMatrix3x3& m, btVector3& Result);
BBAEXPcint M9scaled (btMatrix3x3& m, btVector3 &s);
BBAEXPfloat M9determinant (btMatrix3x3& m);
BBAEXPcint M9adjoint (btMatrix3x3& m);
BBAEXPcint M9absolute (btMatrix3x3& m);
BBAEXPcint M9transpose (btMatrix3x3& m);
BBAEXPcint M9inverse (btMatrix3x3& m);
BBAEXPcint M9transposeTimes (btMatrix3x3& m, const btMatrix3x3 &m2);
BBAEXPcint M9timesTranspose (btMatrix3x3& m, const btMatrix3x3 &m2);
BBAEXPfloat M9tdotx (btMatrix3x3& m, btVector3 &v);
BBAEXPfloat M9tdoty (btMatrix3x3& m, btVector3 &v);
BBAEXPfloat M9tdotz (btMatrix3x3& m, btVector3 &v);
BBAEXPcint M9diagonalize (btMatrix3x3& m, btMatrix3x3 &rot, float threshold, int maxSteps);
BBAEXPfloat M9cofac (btMatrix3x3& m, int r1, int c1, int r2, int c2);

BBAEXPcint M9toBB(btMatrix3x3& m);
BBAEXPcint BBtoM9(btMatrix3x3& m);